package cn.smile.auth.rest;

import cn.smile.auth.service.LoginService;
import cn.smile.bean.form.login.LoginForm;
import cn.smile.bean.form.login.LoginPhoneForm;
import cn.smile.commons.response.MyResult;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

/**
 * @author smile-jt
 */
@RestController
@RequestMapping("api/auth")
public class LoginController {

    @Resource
    private LoginService service;

    @PostMapping(value = "login")
    public MyResult<String> login(HttpServletRequest request, @Valid @RequestBody LoginForm form) {
        return MyResult.OK(service.loginSys(request, form));
    }

    @PostMapping(value = "loginPhone")
    public MyResult<String> loginPhone(HttpServletRequest request, @Valid @RequestBody LoginPhoneForm form) {
        return MyResult.OK(service.loginPhone(request, form));
    }

    @GetMapping(value = "refreshEff")
    public MyResult<String> refresh() {
        service.refreshEff();
        return MyResult.OK();
    }

    @GetMapping(value = "logout")
    public MyResult<Boolean> logout() {
        return MyResult.OK(service.logoutSys());
    }
}
